<div id="main_send_good">
<input type="hidden" id="orderIds" value="#(orderIds)"/>
<table class="table table-striped table-bordered" style="margin-right: 20px;">
		    <thead class="js-freight-cost-list-header">
		    	<tr><td>商品</td><td>数量</td><td>金额（元）</td></tr>
		    </thead>
		    <tbody>
                  #for(items: orderDetailResultDto.orderItems)
				    <tr>
						<td><img src="#(items.productImg)" style="margin: 2px" width="30" height="30" number="1">#if(items.productName.length()>8) #textcut(items.productName, 8) #else #(items.productName) #end</td>
						<td>#(items.quantity)</td>
						<td>#(items.totalPrice)</td>
					</tr>
			      #end
            </tbody>
		</table>
		
		 <div style="padding-top: 20px;">
               <label class="col-md-2 control-label">物流公司:</label>
               <div class="col-md-10">
                   <div  id="error_exp_key">
                   		 <select id="exp_key"  name="exp_key" class="form-control" style="width:180px;display: inline;" onchange="elseInput()">
							<option value="">请选择快递公司</option>
							#for(company : expresscomps) 
							<option value="#(company.expKey )" expcode = "#(company.expCode )" expName="#(company.expName )">
							#(company.expName)
							</option>
							#end
							<option value="else">其他物流</option>
               			  </select>
               			  &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="elseExp" name="elseExp" class="form-control" value="" style="display:none;" placeholder="请输入物流公司名称" />
               			<label class="error_exp_key col-md-12" style="color:red;" for="exp_key"></label>
                   </div>
               </div>
         </div>
         <br/>
         <div style="padding-top: 35px;">
             <label class="col-md-2 control-label">快递单号:</label>
             <div class="col-md-10">
                <div  id="error_bill_number">
	                <input type="text" id="bill_number" name="bill_number" class="form-control" value="" style="width:180px;"/>
	                <label class="error_bill_number" style="color:red;" for="bill_number"></label>
	         	</div>
             </div>
         </div>
         <br/>
         <div style="padding-top: 35px;">
              <label class="col-md-2 control-label">收货地址:</label>
              <div class="col-md-10">
            	#for(resultDto : orderDetailResultDto)
         			<span>#(resultDto.receiverProvince) #(resultDto.receiverCity) #(resultDto.receiverCountry)  #(resultDto.receiverAddr),#(resultDto.receiverName),#(resultDto.receiverPhone)</span>
         		#end
              </div>     
         </div>
         
		<div class="panel-default">
		  	<div class="panel-body" align="right">
				<button type="button" onclick="sendGood();" class="btn btn-primary btn-sm">确认发货</button>
		  	</div>
	  	</div>
</div>
	  	
<script type="text/javascript">
function sendGood(){
	clearError()
	var params={}, error = {};
	var orderIds = $("#orderIds").val(), exp_key = $("#exp_key").children('option:selected').val(), bill_number = $("#bill_number").val(),exp_name = $("#elseExp").val();
	params.orderIds = $.trim(orderIds);
	if($.trim(exp_key) =="" || ($.trim(exp_key) =="else" && $.trim(exp_name) =="")){
		error.error_exp_key = "物流公司不能为空"; 
	}else if($.trim(exp_key) =="else"){
		error.exp_key=""; params.exp_name = $.trim(exp_name);params.exp_key = $.trim(exp_key);
	}
	else{
		error.exp_key=""; params.exp_key = $.trim(exp_key);
	}
	if($.trim(bill_number) =="") {error.error_bill_number = "快递单号不能为空"; } else {error.bill_number=""; params.bill_number = $.trim(bill_number);}
	var hasError = false;
	for(var key in error){
		if(error[key]!=""){
			if(!hasError) hasError = true;
			$("#"+key).addClass("has-error");
			$("#"+key).find("label").text(error[key]);
		}else{
			$("#"+key).removeClass("has-error");
			$("#"+key).find("label").empty();
		}
	}
	if(hasError) return false;
	$("#main_send_good").mask("正在发货...");
	obz.ajaxJson(obz.ctx+"/order/saveSendGoods", params, function(json) {
		$("#main_send_good").unmask();
		 if(json.code!=200){
			BootstrapDialog.alert({title:'提示', message:json.msg});
		}else{
			obz.msg('发货成功', function(){
				location.reload();
			});						
		}
	},"json");
}

function clearError(){
	$(".error_bill_number,.error_exp_key").empty();
	var exp_key=$("select[name='exp_key']");
	exp_key.css("border-color", "");
	var bill_number=$("input[name='bill_number']");
	bill_number.css("border-color", "");
}

function elseInput(){
	var valExp = $("#exp_key").val();
	if(valExp != null && valExp == "else"){
		$("#elseExp").attr("style","width:180px;display:inline;")
	}else{
		$("#elseExp").attr("style","display:none;")
	}
}
</script>